from typing import Annotated, Literal

Operator = Literal["+", "-", "*", "/"]


def calculator(a: int, b: int, operator: Annotated[Operator, "operator"]) -> int:
    if operator == "+":
        return a + b
    elif operator == "-":
        return a - b
    elif operator == "*":
        return a * b
    elif operator == "/":
        return int(a / b)
    else:
        raise ValueError("Invalid operator")
def add(a:int, b:int)->int:
    """ add a and b """
    return a + b
def multiply(a:int, b:int)->int:
    """a multiply b"""
    return a * b

import os

from autogen import ConversableAgent

config_list = [
    {
        # Let's choose the Meta's Llama 3.1 model (model names must match Ollama exactly)
        #"model": "llama3.1:8b",
        "model":"qwen2.5-coder:latest",
        #"model": "deepseek-r1:7b",
        # We specify the API Type as 'ollama' so it uses the Ollama client class
        "api_type": "ollama",
        "stream": False,
        "client_host": "http://192.168.99.142:11434",
    }
]
# Let's first define the assistant agent that suggests tool calls.
assistant = ConversableAgent(
    name="Assistant",
    system_message="You are a helpful AI assistant. "
    "You can help with simple calculations. "
    "Return 'TERMINATE' when the task is done.",
    llm_config={"config_list": config_list},
)

# The user proxy agent is used for interacting with the assistant agent
# and executes tool calls.
user_proxy = ConversableAgent(
    name="User",
    llm_config=False,
    is_termination_msg=lambda msg: msg.get("content") is not None and "TERMINATE" in msg["content"],
    human_input_mode="NEVER",
)

"""
# Register the tool signature with the assistant agent.
assistant.register_for_llm(name="add", description="A simple calculator")(add)

# Register the tool function with the user proxy agent.
user_proxy.register_for_execution(name="add")(add)

from autogen import register_function
# Register the calculator function to the two agents.
register_function(
    add,
    caller=assistant,  # The assistant agent can suggest calls to the calculator.
    executor=user_proxy,  # The user proxy agent can execute the calculator calls.
    name="calculator",  # By default, the function name is used as the tool name.
    description="A simple calculator",  # A description of the tool.
)

"""
from autogen import register_function
# Register the calculator function to the two agents.
register_function(
    add,
    caller=assistant,  # The assistant agent can suggest calls to the calculator.
    executor=user_proxy,  # The user proxy agent can execute the calculator calls.
    name="add",  # By default, the function name is used as the tool name.
    description="add a and b",  # A description of the tool.
)
register_function(
    multiply,
    caller=assistant,  # The assistant agent can suggest calls to the calculator.
    executor=user_proxy,  # The user proxy agent can execute the calculator calls.
    name="multiply",  # By default, the function name is used as the tool name.
    description="multiply  a and b",  # A description of the tool.
)
#chat_result = user_proxy.initiate_chat(assistant, message="What is (44232 + 13312 / (232 - 32)) * 5?")
chat_result = user_proxy.initiate_chat(assistant, message="What is (4114 + 1311 + 1213 + 3211)?")